package com.zfk.framework.testcasepool;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import com.zfk.framework.models.CaseData;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class TestCaseProvider {
    private static final Logger logger = LogManager.getLogger(TestCaseProvider.class);
    public static Iterator<Object[]> getTestCaseData(List<String> caseIdList) {
        List<Object[]> testCaseData = new ArrayList<>();
        try {

            for (String caseId : caseIdList) {
                CaseData caseData = TestCaseInitializer.casePool.get(caseId);
                if (caseData != null) {
                    logger.info("从用例池中获取到{}测试用例", caseId);
                    testCaseData.add(new Object[]{caseId, caseData});
                } else {
                    logger.error("用例{}不存在", caseId);
                }
            }
            if (testCaseData.isEmpty()) {
                logger.error("没有获取到任何可用的测试用例");
                throw new IllegalArgumentException("没有获取到任何可用的测试用例");
            }
        } catch (Exception e) {
            logger.error("获取测试用例数据失败: {}", e.getMessage(), e);
            throw new RuntimeException("测试用例数据提供者初始化失败", e);
        }
        return testCaseData.iterator();
    }
}
